<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" href="../../css/aui.css">
		<link rel="stylesheet" type="text/css" href="../../css/aliance.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/allsearch.css" />
		<script src="../../js/api.js"></script>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/libs/swiper.min.js"></script>
		<script src="../../js/vue.min.js"></script>
		<script src="../../js/vue-resource.min.js"></script>
		<script src="../../js/aui-toast.js"></script>
		<script src="../../js/common.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.8&key=1541c9a07778b4a05f644ce5f37391aa&plugin=AMap.Geocoder"></script>
		<script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
		<style>
			.hmShopList> :first-child {
				margin-top: 0;
			}
		</style>
		<script>
			setToken();
			$(function() {
				var app = new Vue({
					el: '#app',
					data: {
						fenlei: [],
						Jing: [],
						Wei: []
					},
					mounted: function() {
					},
					methods: {
						addVal: function(){
							var val = $('#allSearch').val();
							var jing = sessionStorage.getItem('jing');
							var wei = sessionStorage.getItem('wei');
							if(jing!=null&&!wei!=null){
								$.get(SURL + 'app/shops/storePos', {
									"lng": jing,
									"lat": wei,
									"shopName": val,
									"industry": '1'
								}, function(res) {
									if(res.data.length==0){
										app.fenlei = []
										console.log('没有')
										console.log(app.fenlei)
									}else{
										app.fenlei = []
										for(var i=0; i<res.data.length; i++){
											app.fenlei.push(res.data[i]);
										}
									}
								})
							}
						},
						go_details: function(id) { //方法
								location.href = "details.html?shopId=" + id;

						},
					}
				});
				
				
			var map, geolocation;
				//加载地图，调用浏览器定位服务
				map = new AMap.Map('container', {
					resizeEnable: true,
					zoom: 18
				});
				map.plugin('AMap.Geolocation', function() {
					geolocation = new AMap.Geolocation({
						enableHighAccuracy: true, //是否使用高精度定位，默认:true
						timeout: 10000, //超过10秒后停止定位，默认：无穷大
						buttonOffset: new AMap.Pixel(10, 30), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
						zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
						buttonPosition: 'RB'
					});
					map.addControl(geolocation);
					geolocation.getCurrentPosition();
					AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
					AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
				});
				//解析定位结果
				var Jing = [];
				var Wei = [];
				var Zong = [];
				var storePos = [];

				function onComplete(data) {
					Jing.push(data.position.getLng());
					sessionStorage.setItem('jing', data.position.getLng());
					Wei.push(data.position.getLat());
					sessionStorage.setItem('wei', data.position.getLat());
					Zong.push(data.position.getLng(), data.position.getLat());
				}
				//解析定位错误信息
				function onError(data) {
					alert('定位失败');
				}
			

			})


//			function addVal(obj) {
//				console.log('hellow')
//				var jing = sessionStorage.getItem('jing');
//				var wei = sessionStorage.getItem('wei');
//				if(jing!=null&&!wei!=null){
//					$.get(SURL + 'app/shops/storePos', {
//						"lng": jing,
//						"lat": wei,
//						"shopName": obj.value,
//						"industry": '1'
//					}, function(res) {
//						if(res.data.length==0){
//							console.log('没有')
//						}else{
//							for(var i=0; i<res.data.length; i++){
//								app.fenlei.push(res.data[i]);
//							}
//						}
////						for(var i = 0; i < res.data.length; i++) {
////							app.fenlei.push(res.data[i]);
////							console.log(fenlei)
////						}
//					})
//				}
//			}
		</script>

		<title>搜索</title>
	</head>

	<body>
		<div id="app">
		<div class="hm-Bar">
			<div class="hm-Map">
				<div class="hm-Map-left">
					<img src="../../img/sreachIconWhite.png" />
				</div>
				<div class="hm-Map-center">
					<input type="text" placeholder="搜索" id="allSearch" @input="addVal()" />
				</div>
				<div class="hm-Map-right">
					<a href="index.html">取消</a>
				</div>
			</div>
		</div>
		<div>
			<div class="nearby-shops">
				<div class="hmMIn">
					<div class="hmShops">
						<ul class="hmShopList">
							<li class="nearby-shop clearFix" v-for="(j,i) in fenlei" @click="go_details(j.shopId)">
								<img class="hmShopImg" :src="imgUrl+j.logo" alt="" />
								<div class="hmShopBox">
									<div class="contTit">
										{{j.shopName}}
									</div>
									<div class="contRate clearFix">
										{{j.address}}
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div>
			</div>

		</div>
			
		</div>
	</body>

</html>